//短信宝 http://www.smsbao.com/openapi/
const Promise = require('bluebird');
const request = require('request');

/**
 * 发送验证码
 let form = {
    "u": "wuxingtea",
    "p": "",
    "m": "",
    "c": "您的验证码为 1234【五行茶】"
 }
 */
exports.sendCode = function (form) {
    return new Promise(function (resolve) {
        request.get({
            url: 'http://api.smsbao.com/sms',
            qs: form
        }, function (err, response, result) {
            if (err) {
                console.error('\n', err.stack || err.message);
                return resolve({success: false});
            }
            if (result == 0) {
                return resolve({success: true, data: result});
            }
            return resolve({success: false, data: result});
        });
    });
}